package com.kun.portal.webframe.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kun.portal.webframe.util.MessageFilter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/5/11.
 */
@Controller
//  /api/userSettingmessageFilter
@RequestMapping({"/api/userSetting"})
public class UserSettingControlller {
@RequestMapping(
   value = {"backImage"},
        method={RequestMethod.POST}
)
    public void setBackImg(@RequestParam String url,HttpServletResponse response,HttpServletRequest request){
    boolean create=false;
    System.out.println(url);
    Cookie cookies[] = request.getCookies();
    for(Cookie cookie : cookies){
        if(cookie.getName().equals("url")){
            create=true;
            cookie = new Cookie("url",url);
            cookie.setMaxAge(60*60*24*365);
            cookie.setDomain("");
            cookie.setPath("/");
            response.addCookie(cookie);
        }
    }
    if(!create){
        Cookie cookie = new Cookie("url",url);
        cookie.setMaxAge(60*60*24*365);
        cookie.setDomain("");
        cookie.setPath("/");
        response.addCookie(cookie);
    }


    }

    @RequestMapping(
            value = {"messageFilter"},
            method={RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public Map messageFilter(){
                return   MessageFilter.messageFilter;
    }

}
